﻿using System.Web;
using Common.Model;

namespace Common.Context
{
    public class ManagerContext
    {

        public static Cd_User UserInfo
        {
            get { return GetSessionUserInfo(); }
        }

        private static Cd_User GetSessionUserInfo()
        {
            Cd_User manager = HttpContext.Current.Session[Key.MANAGER_INFO] as Cd_User;
            if (manager == null)
            {
                string userName = Utils.GetCookie(Key.MANAGER_NAME);
                string password = Utils.GetCookie(Key.MANAGER_PASS);
                if (userName != "" || password != "")
                {
                    manager = Factory.Factory.UserService().Login(userName, Security.MD5Encrypt(password));
                    if (manager != null)
                    {
                        HttpContext.Current.Session[Key.MANAGER_INFO] = manager;
                        return manager;
                    }
                }
                return null;
            }
            return manager;
        }
    }
}